# encoding:utf-8
#from RecvMsgJudge import msgJudge

#from formRegister import formRegisterDialog
#from formLogin import formLoginDialog
#from CreateData import CreateData
#from ComHelper import ComHelper
#from NewBatchDIalog import NewBatchDialog
from Mod_language import Cls_ui_text
import time
import json
import re
import wx


class Frm_main(wx.Frame):
    def __init__(self, parent, id, language):
        # 根据用户选择语言配置界面上显示的文字
        uitext = Cls_ui_text()
        self.language = language
        self.UI_TEXT = uitext.LangConfig(self.language)
        wx.Frame.__init__(self, parent=parent, id=id, title=self.UI_TEXT["TEXT1"], size=(1000, 900),
                          style=wx.MAXIMIZE | wx.DEFAULT_FRAME_STYLE)
        #初始化控件
        self.InitController() 
        #绑定事件
        self.BindEvent()


    def InitController(self):
        self.panel = wx.Panel(parent=self, id=-1)
        self.panel.SetBackgroundColour('lightblue')
        self.InitStatusbar()  # 状态栏初始化
        self.InitMenu()  # 菜单初始化
        self.InitToolbar()  # 工具栏初始化

    def BindEvent(self):
        self.Bind(wx.EVT_CLOSE, self.OnClose, self)



    def InitStatusbar(self):
        """状态栏初始化"""
        statusbar = self.CreateStatusBar(number=3, style=wx.STB_DEFAULT_STYLE, id=-1)
        statusbar.SetStatusWidths([-3, -2, -1])
        statusbar.SetStatusStyles([wx.SB_SUNKEN, wx.SB_SUNKEN, wx.SB_SUNKEN])
        statusbar.SetStatusText("Field2", 1)
        statusbar.SetStatusText("Field3", 2)
        self.stb_timer = wx.Timer(self)  # 创建定时器
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.stb_timer)  # 绑定一个定时器事件
        self.stb_timer.Start(1000)

    def InitMenu(self):
        """菜单初始化"""
        menuBar = wx.MenuBar()  # 创建菜单栏

        menuBatchManage = wx.Menu()  # 创建批次管理菜单
        menuBar.Append(menuBatchManage, title=self.UI_TEXT["TEXT2"] + "(&B)")  # 将批次管理菜单添加到菜单栏
        # 创建菜单项，并添加到批次管理菜单
        new_item = wx.MenuItem(menuBatchManage, id=0, text=self.UI_TEXT["TEXT3"], kind=wx.ITEM_NORMAL)
        delete_item = wx.MenuItem(menuBatchManage, id=1, text=self.UI_TEXT["TEXT4"], kind=wx.ITEM_NORMAL)
        cur_item = wx.MenuItem(menuBatchManage, id=2, text=self.UI_TEXT["TEXT5"], kind=wx.ITEM_NORMAL)
        op_hty_item = wx.MenuItem(menuBatchManage, id=3, text=self.UI_TEXT["TEXT6"], kind=wx.ITEM_NORMAL)
        clo_hty_item = wx.MenuItem(menuBatchManage, id=4, text=self.UI_TEXT["TEXT7"], kind=wx.ITEM_NORMAL)
        mer_hty_item = wx.MenuItem(menuBatchManage, id=5, text=self.UI_TEXT["TEXT8"], kind=wx.ITEM_NORMAL)
        spl_hty_item = wx.MenuItem(menuBatchManage, id=6, text=self.UI_TEXT["TEXT9"], kind=wx.ITEM_NORMAL)
        menuBatchManage.Append(new_item)
        menuBatchManage.Append(delete_item)
        menuBatchManage.Append(cur_item)
        menuBatchManage.AppendSeparator()
        menuBatchManage.Append(op_hty_item)
        menuBatchManage.Append(clo_hty_item)
        menuBatchManage.Append(mer_hty_item)
        menuBatchManage.Append(spl_hty_item)
        self.Bind(wx.EVT_MENU, self.on_BatchManage_click, id=0, id2=6)

        menuParamControl = wx.Menu()  # 创建参数控制菜单
        menuBar.Append(menuParamControl, title=self.UI_TEXT["TEXT10"] + "&(C)")
        ctl_sty_set_item = wx.MenuItem(menuParamControl, id=7, text=self.UI_TEXT["TEXT11"], kind=wx.ITEM_NORMAL)
        loc_ctl_sty_item = wx.MenuItem(menuParamControl, id=8, text=self.UI_TEXT["TEXT12"], kind=wx.ITEM_NORMAL)
        ctl_sty_upd_item = wx.MenuItem(menuParamControl, id=9, text=self.UI_TEXT["TEXT13"], kind=wx.ITEM_NORMAL)
        menuParamControl.Append(ctl_sty_set_item)
        menuParamControl.Append(loc_ctl_sty_item)
        menuParamControl.Append(ctl_sty_upd_item)

        menuParamCalculate = wx.Menu()  # 创建参数计算菜单
        menuBar.Append(menuParamCalculate, title=self.UI_TEXT["TEXT14"] + "&(L)")
        cal_opt_item = wx.MenuItem(menuParamCalculate, id=10, text=self.UI_TEXT["TEXT15"], kind=wx.ITEM_NORMAL)
        loc_fmla_item = wx.MenuItem(menuParamCalculate, id=11, text=self.UI_TEXT["TEXT16"], kind=wx.ITEM_NORMAL)
        fmla_upd_item = wx.MenuItem(menuParamCalculate, id=12, text=self.UI_TEXT["TEXT17"], kind=wx.ITEM_NORMAL)
        menuParamCalculate.Append(cal_opt_item)
        menuParamCalculate.Append(loc_fmla_item)
        menuParamCalculate.Append(fmla_upd_item)

        menuDataAnalysis = wx.Menu()  # 创建数据分析菜单
        menuBar.Append(menuDataAnalysis, title=self.UI_TEXT["TEXT18"] + "&(A)")
        xxxx1_item = wx.MenuItem(menuDataAnalysis, id=13, text=self.UI_TEXT["TEXT19"], kind=wx.ITEM_NORMAL)
        xxxx2_item = wx.MenuItem(menuDataAnalysis, id=14, text=self.UI_TEXT["TEXT20"], kind=wx.ITEM_NORMAL)
        menuDataAnalysis.Append(xxxx1_item)
        menuDataAnalysis.Append(xxxx2_item)

        menuWindow = wx.Menu()  # 创建窗口菜单
        menuBar.Append(menuWindow, title=self.UI_TEXT["TEXT21"] + "&(W)")
        dev_sta_item = wx.MenuItem(menuWindow, id=15, text=self.UI_TEXT["TEXT22"], kind=wx.ITEM_CHECK)
        cur_data_item = wx.MenuItem(menuWindow, id=16, text=self.UI_TEXT["TEXT23"], kind=wx.ITEM_CHECK)
        hty_data_item = wx.MenuItem(menuWindow, id=17, text=self.UI_TEXT["TEXT24"], kind=wx.ITEM_CHECK)
        graph_item = wx.MenuItem(menuWindow, id=18, text=self.UI_TEXT["TEXT25"], kind=wx.ITEM_CHECK)
        menuWindow.Append(dev_sta_item)
        menuWindow.Append(cur_data_item)
        menuWindow.Append(hty_data_item)
        menuWindow.Append(graph_item)
        menuWindow.Check(id=18, check=True)

        menuData = wx.Menu()  # 创建数据管理菜单
        menuBar.Append(menuData, title=self.UI_TEXT["TEXT26"] + "&(D)")
        export_item = wx.MenuItem(menuData, id=19, text=self.UI_TEXT["TEXT27"], kind=wx.ITEM_NORMAL)
        import_item = wx.MenuItem(menuData, id=20, text=self.UI_TEXT["TEXT28"], kind=wx.ITEM_NORMAL)
        download_item = wx.MenuItem(menuData, id=21, text=self.UI_TEXT["TEXT29"], kind=wx.ITEM_NORMAL)
        upload_item = wx.MenuItem(menuData, id=22, text=self.UI_TEXT["TEXT30"], kind=wx.ITEM_NORMAL)
        data_dele_item = wx.MenuItem(menuData, id=23, text=self.UI_TEXT["TEXT31"], kind=wx.ITEM_NORMAL)
        menuData.Append(export_item)
        menuData.Append(import_item)
        menuData.Append(download_item)
        menuData.Append(upload_item)
        menuData.Append(data_dele_item)

        menuConfiguration = wx.Menu()  # 创建系统配置菜单
        menuBar.Append(menuConfiguration, title=self.UI_TEXT["TEXT32"] + "&(G)")
        db_item = wx.MenuItem(menuConfiguration, id=24, text=self.UI_TEXT["TEXT32A"], kind=wx.ITEM_NORMAL)
        user_reg_item = wx.MenuItem(menuConfiguration, id=25, text=self.UI_TEXT["TEXT33"], kind=wx.ITEM_NORMAL)
        user_login_item = wx.MenuItem(menuConfiguration, id=26, text=self.UI_TEXT["TEXT34"], kind=wx.ITEM_NORMAL)
        pc_bind_item = wx.MenuItem(menuConfiguration, id=27, text=self.UI_TEXT["TEXT35"], kind=wx.ITEM_NORMAL)
        fer_para_item = wx.MenuItem(menuConfiguration, id=28, text=self.UI_TEXT["TEXT36"], kind=wx.ITEM_NORMAL)
        data_intef_item = wx.MenuItem(menuConfiguration, id=29, text=self.UI_TEXT["TEXT36A"], kind=wx.ITEM_NORMAL)
        menuConfiguration.Append(db_item)
        menuConfiguration.Append(user_reg_item)
        menuConfiguration.Append(user_login_item)
        menuConfiguration.Append(pc_bind_item)
        menuConfiguration.Append(fer_para_item)
        menuConfiguration.Append(data_intef_item)


        menuAuthority = wx.Menu()  # 创建权限菜单
        menuBar.Append(menuAuthority, title=self.UI_TEXT["TEXT37"] + "&(T)")
        autr1_item = wx.MenuItem(menuAuthority, id=30, text=self.UI_TEXT["TEXT38"], kind=wx.ITEM_CHECK)
        autr2_item = wx.MenuItem(menuAuthority, id=31, text=self.UI_TEXT["TEXT39"], kind=wx.ITEM_CHECK)
        autr3_item = wx.MenuItem(menuAuthority, id=32, text=self.UI_TEXT["TEXT40"], kind=wx.ITEM_CHECK)
        autr4_item = wx.MenuItem(menuAuthority, id=33, text=self.UI_TEXT["TEXT41"], kind=wx.ITEM_CHECK)
        autr5_item = wx.MenuItem(menuAuthority, id=34, text=self.UI_TEXT["TEXT42"], kind=wx.ITEM_CHECK)
        alter_pwd_item = wx.MenuItem(menuAuthority, id=35, text=self.UI_TEXT["TEXT43"], kind=wx.ITEM_CHECK)
        menuAuthority.Append(autr1_item)
        menuAuthority.Append(autr2_item)
        menuAuthority.Append(autr3_item)
        menuAuthority.Append(autr4_item)
        menuAuthority.Append(autr5_item)
        menuAuthority.Append(alter_pwd_item)
        menuAuthority.Check(id=34, check=True)
        self.SetMenuBar(menuBar)  # 将菜单栏添加至框架

    def on_BatchManage_click(self, event):
        event_id = event.GetId()
        print(event_id)
        

    def InitToolbar(self):
        """工具栏初始化"""
        pass

    def OnTimer(self, event):
        """状态栏时钟"""
        t = time.localtime(time.time())
        StrYMDt = time.strftime("%Y-%B-%d %I:%M:%S", t)
        self.SetStatusText(StrYMDt, 0)

    def WindowSwitch(self, windowMenu, menuItemId):
        """展示窗口切换"""
        pass

    def AuthoritySwitch(self, authorityMenu, menuItemId):
        """操作权限切换"""
        pass

    def OnClose(self, event):
        # self.ser.com_close()
        exit()

